package com.service.impl;

import com.bean.entity.AllStudentScore;
import com.bean.pojo.PageAssistant;
import com.bean.vo.AllStudentScoreVo;
import com.dao.AllStudentScoreMapper;
import com.service.AllStudentScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 所有学生成绩表基础业务逻辑实现
 */
@Service
public class AllStudentScoreServiceImpl implements AllStudentScoreService {

    @Autowired
    private AllStudentScoreMapper allStudentScoreMapper;

    public int save(AllStudentScore t) throws Exception {
        return allStudentScoreMapper.insert(t);
    }

    public int remove(AllStudentScore t) throws Exception {
        return allStudentScoreMapper.delete(t);
    }

    public int modify(AllStudentScore t) throws Exception {
        return allStudentScoreMapper.update(t);
    }

    public AllStudentScoreVo unique(AllStudentScore t) throws Exception {
        List<AllStudentScoreVo> allStudentScoreVoList = allStudentScoreMapper.select(t);
        if (allStudentScoreVoList.size()!=1) throw new Exception("您要查询的学生分数暂未找到！");
        return allStudentScoreVoList.get(0);
    }

    public List<AllStudentScoreVo> query(AllStudentScore t) {
        return allStudentScoreMapper.select(t);
    }

    public PageAssistant<AllStudentScoreVo> queryByPage(Map<String, Object> map, PageAssistant<AllStudentScoreVo> pa) {
        //查询并设置总记录数
        pa.setCount(allStudentScoreMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());
        //查询并设置页面内容
        pa.setItems(allStudentScoreMapper.selectByPage(map));
        return pa;
    }
}
